//index.js
//获取应用实例
var app = getApp()
Page({
  data: {
    navbar: ['头条', '娱乐', '财经','军事','科技'],
    currentTab: 0 ,
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,  
  },
  navbarTap: function(e){  
    this.setData({  
      currentTab: e.currentTarget.dataset.idx  
    })  
    var index = parseInt(e.currentTarget.dataset.idx);
    var cid = parseInt(index) + parseInt(1);
    console.log(cid)
    var that = this
    //调用应用实例的方法获取全局数据
    wx.request({
      url: 'http://www.luck7.top/face/index/slide/cid/'+cid,
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        that.setData({
          slide: res.data
        })
      }
    })
    wx.request({
      url: 'http://www.luck7.top/face/index/news/type/' + cid,
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        that.setData({
          news: res.data
        })
      }
    })
    console.log(parseInt(index) + parseInt(1));

  },  
  onLoad: function () {
    wx.showToast({
      title: '加载成功',
      icon: 'succes',
      duration: 1000,
      mask: true
    })
    var that = this
    //调用应用实例的方法获取全局数据
    wx.request({
      url: 'http://www.luck7.top/face/index/index',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        that.setData({
          texts:res.data
        })
      }
    })
    wx.request({
      url: 'http://www.luck7.top/face/index/moren',
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        that.setData({
          newss: res.data
        })
      }
    })
    app.getUserInfo(function(userInfo){
      //更新数据
      that.setData({
        userInfo:userInfo
      })
    })
  }
})
